      function checkAvailability(isbn, callback) {
      
        var xhr = new XMLHttpRequest();
        xhr.onreadystatechange = function(data) {
          if (xhr.readyState == 4) {
            if (xhr.status == 200) {
              var alert_level = localStorage["alert_level"];
              var data = xhr.responseText;
              var bookAvailable = /Available/;
              var notFound = /no direct matches/;
              var message;
              var found = false;
              
              if (! alert_level) {

                alert_level = "all";
                localStorage["alert_level"] = alert_level;

              }
              
              if (notFound.test(data)) {
              
                if (alert_level != "all"){
                  return;
                }
                
                message = chrome.i18n.getMessage("bookNotFound");
              }
              else {

                found = true;

                if (bookAvailable.test(data)) {
                
                  message = chrome.i18n.getMessage("bookAvailable");
                  
                }
                else {
                
                  if (alert_level == "available")
                  {
                    return;
                  }
                
                  message = chrome.i18n.getMessage("bookNotAvailable");
                }
                
              }
              
              callback({"found":found,"message":message});
              
            }
            else {
              callback(null);
            }
          }
        }

        var url = 'http://ottawa.bibliocommons.com/search?custom_query=Identifier%3A(' + isbn + ')';
        xhr.open('GET', url, true);
        xhr.send();
        
      } // checkAvailability
      
      function checkSearch(index, isbn, callback){

        var xhr = new XMLHttpRequest();
        
        xhr.index = index;
        
        xhr.onreadystatechange = function(data) {
          if (xhr.readyState == 4) {
            if (xhr.status == 200) {

              var data = xhr.responseText;
              
              var notFound = /Sorry, could not find anything matching/g;
              
              var found = ! notFound.test(data);
              
              if (! found) {
                callback(this.index, found);
              }

            }
          }
        }

        var url = 'http://ottawa.bibliocommons.com/search?custom_query=Identifier%3A(' + isbn + ')';
        xhr.open('GET', url, true);
        xhr.send();

      }  // checkSearch
      
      // wire up the action, passing through the callback
      function onRequest(request, sender, callback) {
        if (request.action == 'checkAvailability') {
          checkAvailability(request.isbn, callback);
        }
        if (request.action == 'checkSearch') {
        
          var check_search = localStorage["check_search"];

          if (! check_search) {

            check_search = "yes";
            localStorage["check_search"] = check_search;

          }
          if (check_search == "yes") {
            checkSearch(request.index, request.isbn, callback);
          }
        }
      };

      chrome.extension.onRequest.addListener(onRequest);
      
 
